#ifndef MEMDATABASE_H
#define MEMDATABASE_H
#include <string>
#include "database.h"
#include <map>
#include <set>
#include <iostream>
#include <iterator>
#include <map>
using namespace std;

class memdatabase : public database_interface {
	typedef  unsigned int entry_id;
	typedef string group_name;
	typedef map<entry_id, news_entry> news_group;
	typedef map<group_name, news_group> database;
	
	
	//new typedefs for groupid
	typedef unsigned int group_id;
	typedef set<group_id> group_ids;
	typedef map<group_name, group_id> idmap;
	typedef map<group_id, group_name> idmapinv;


	public:
		memdatabase();
		~memdatabase();
	
		bool create_newsgroup(string group);

		/* Creates a news entry.*/
		pair<bool, unsigned int> put(const unsigned int group, const string title, const string author, const string text);

		/* Retrieves a news entry.*/
		pair<int, map<string, string> > get(const unsigned int group_id, const unsigned int article_id);
	
		vector<pair<unsigned int, string> > get_newsgroups();

		bool remove_newsgroup(const unsigned int group_id);

		vector<pair<unsigned int, string> > get_news_entries(unsigned int group);

		/* Removes a news entry.*/
		int remove(const unsigned int group_id, const unsigned int article_id);

	private :
		database db;
		group_ids ids;
		idmap idm;
		idmapinv idminv;
		unsigned int current_article_id;

};

#endif
